#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
//	system("start https://www.lanqiao.cn/problems/19869/learning/");

    string s;
    cin >> s;

    int ans = 0;

    bool flag = 0;
    char pre = 'L';
    for(int i = 0; i < s.size() - 1; i++) {
        if(s[i] == 'L' && s[i + 1] == 'L')
            ans++;
        if(s[i] == 'Q' && s[i + 1] == 'L')
            ans++;
        if(s[i] == 'L' && s[i + 1] == 'Q' && pre == 'L')
            ans++;
        if(s[i] == 'Q' && s[i + 1] == 'Q' && !flag)
            ans++, flag = 1;
        pre = s[i];
    }

    cout << ans;

    return 0;
}

